package com.blyat.xsoft.kernel.exception.code;

/**
 * @author syh
 * @date 2019/10/15
 **/
public enum DefaultErrorResult implements ErrorResult {

    /**
     * http异常
     */
    HTTP_COMMITED("100", "流已关闭"),
    URL_REDIRECT_ERROR("103", "地址跳转错误"),

    /**
     * 基本异常
     */
    FAILURE("0", "{0}！"),
    MVC_PARAMETER_MISSING("25", "请求发生时丢失请求参数：{0}！"),
    PARAMETER_ERROR("26", "参数JSON解析时异常！"),
    ILLEGAL_CHARACTER("50", "非法字符！");

    String code, message;

    DefaultErrorResult(String code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public String getResult() {
        return code;
    }

    @Override
    public String getMessage(Object... args) {
        if (args == null || args.length <= 0) return this.message;

        try {
            return String.format(this.message, args);
        } catch (Exception e) {
            return this.message;
        }
    }
}
